package com.ruoyi.project.WebMoudle.WxShopWords.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.WxShopWords.domain.WxShopWords;
import com.ruoyi.project.WebMoudle.WxShopWords.service.IWxShopWordsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 关键字Controller
 * 
 * @author ruoyi
 * @date 2020-06-22
 */
@Controller
@RequestMapping("/WxShopWords/WxShopWords")
public class WxShopWordsController extends BaseController
{
    private String prefix = "WxShopWords/WxShopWords";

    @Autowired
    private IWxShopWordsService wxShopWordsService;

    @RequiresPermissions("WxShopWords:WxShopWords:view")
    @GetMapping()
    public String WxShopWords()
    {
        return prefix + "/WxShopWords";
    }

    /**
     * 查询关键字列表
     */
    @RequiresPermissions("WxShopWords:WxShopWords:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxShopWords wxShopWords)
    {
        startPage();
        List<WxShopWords> list = wxShopWordsService.selectWxShopWordsList(wxShopWords);
        return getDataTable(list);
    }

    /**
     * 导出关键字列表
     */
    @RequiresPermissions("WxShopWords:WxShopWords:export")
    @Log(title = "关键字", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxShopWords wxShopWords)
    {
        List<WxShopWords> list = wxShopWordsService.selectWxShopWordsList(wxShopWords);
        ExcelUtil<WxShopWords> util = new ExcelUtil<WxShopWords>(WxShopWords.class);
        return util.exportExcel(list, "WxShopWords");
    }

    /**
     * 新增关键字
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存关键字
     */
    @RequiresPermissions("WxShopWords:WxShopWords:add")
    @Log(title = "关键字", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxShopWords wxShopWords)
    {
        return toAjax(wxShopWordsService.insertWxShopWords(wxShopWords));
    }

    /**
     * 修改关键字
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WxShopWords wxShopWords = wxShopWordsService.selectWxShopWordsById(id);
        mmap.put("wxShopWords", wxShopWords);
        return prefix + "/edit";
    }

    /**
     * 修改保存关键字
     */
    @RequiresPermissions("WxShopWords:WxShopWords:edit")
    @Log(title = "关键字", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxShopWords wxShopWords)
    {
        return toAjax(wxShopWordsService.updateWxShopWords(wxShopWords));
    }

    /**
     * 删除关键字
     */
    @RequiresPermissions("WxShopWords:WxShopWords:remove")
    @Log(title = "关键字", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxShopWordsService.deleteWxShopWordsByIds(ids));
    }


    /**
     * 修改关键字状态
     */
    @RequiresPermissions("WxShopWords:WxShopWords:edit")
    @Log(title = "关键字", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(WxShopWords wxShopWords)
    {
        return toAjax(wxShopWordsService.updateWxShopWords(wxShopWords));
    }

}
